package com.drought.rained.presenter;

import com.drought.rained.bean.IdentityDataLJ;
import com.drought.rained.business.CustomConsumerLJ;
import com.drought.rained.business.ParamsFactoryLJ;
import com.drought.rained.cache.UserInfoLJ;
import com.drought.rained.mvpview.RealNameAuthMvpViewLJ;
import com.drought.rained.response.AuthInfoResponseLJ;
import com.drought.rained.response.BlankResponseLJ;
import com.drought.rained.response.CompareResultResponseLJ;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.functions.Consumer;

public class RealNameAuthPresenterLJ extends BasePresenterLJ {
    private RealNameAuthMvpViewLJ mvpView;

    public RealNameAuthPresenterLJ(RealNameAuthMvpViewLJ mvpView) {
        this.mvpView = mvpView;
    }

    public void getIdentityInfo() {
        Map<String, Object> map = new HashMap<>();
        map.put("userUuid", UserInfoLJ.getShowUuid());
        List<String> authPageCode = new ArrayList<>();
        authPageCode.add("identity_code");
        map.put("authPageCode", authPageCode);
        toSubScribe(req.getAuthInfoData(UserInfoLJ.getToken(), ParamsFactoryLJ.getCommonParams(map)), new CustomConsumerLJ<AuthInfoResponseLJ>() {
            @Override
            public void call(AuthInfoResponseLJ authInfoResponse) {
                mvpView.onGetDataNext(authInfoResponse);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }

    public void saveIdentity(IdentityDataLJ.IdentityBean identity, List<IdentityDataLJ.ImageInfoBean> imageInfoParams, int pass) {
        Map<String, Object> fromMap = identity.toMap();
        fromMap.put("authPageCode", "identity_code");
        fromMap.put("userUuid", UserInfoLJ.getSaveUuid());
        fromMap.put("imageInfoParams", imageInfoParams);
        fromMap.put("pass",pass);
        if (UserInfoLJ.isUserInformationWrong())
            fromMap.put("isInformationWrong", 1);

        toSubScribe(req.saveIdentity(UserInfoLJ.getToken(), ParamsFactoryLJ.getCommonParams(fromMap)), new CustomConsumerLJ<BlankResponseLJ>() {
            @Override
            public void call(BlankResponseLJ blankResponse) {
                mvpView.onGetDataNext(blankResponse);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });

    }


    public void imgCompare(String firstImagePath, String secondImagePath) {
        Map<String, Object> map = new HashMap<>();
        map.put("userUuid", UserInfoLJ.getSaveUuid());
        map.put("firstImagePath", firstImagePath);
        map.put("secondImagePath", secondImagePath);
        toSubScribe(req.imgCompare(UserInfoLJ.getToken(), ParamsFactoryLJ.getParams(map)), new CustomConsumerLJ<CompareResultResponseLJ>() {
            @Override
            public void call(CompareResultResponseLJ compareResultResponse) {
                mvpView.onGetDataNext(compareResultResponse);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }
}
